package com.splic.web.controller.product;

import java.util.List;
import com.splic.common.utils.StringUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.splic.common.annotation.Log;
import com.splic.common.enums.BusinessType;
import com.splic.product.domain.UserBloodpressureData;
import com.splic.product.service.UserBloodpressureDataService;
import com.splic.common.core.controller.BaseController;
import com.splic.common.core.domain.AjaxResult;
import com.splic.common.utils.poi.ExcelUtil;
import com.splic.common.core.page.TableDataInfo;

/**
 * 用户血压数据Controller
 * 
 * @author singe
 * @date 2022-01-04
 */
@Controller
@RequestMapping("/product/userBloodpressureData")
public class UserBloodpressureDataController extends BaseController
{
    private String prefix = "product/userBloodpressureData";

    @Autowired
    private UserBloodpressureDataService userBloodpressureDataServiceImpl;

    @RequiresPermissions("product:userBloodpressureData:view")
    @GetMapping()
    public String userBloodpressureData()
    {
        return prefix + "/list";
    }

    /**
     * 查询用户血压数据列表
     */
    @RequiresPermissions("product:userBloodpressureData:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(UserBloodpressureData userBloodpressureData)
    {
        startPage();
        List<UserBloodpressureData> list = userBloodpressureDataServiceImpl.selectUserBloodpressureDataList(userBloodpressureData);
        return getDataTable(list);
    }

    /**
     * 新增用户血压数据
     */
    @GetMapping(value = { "/form/{id}", "/form" })
    public String form(@PathVariable(value = "id", required = false) Long id, ModelMap mmap)
    {
        if (StringUtils.isNotNull(id)){
            mmap.put("userBloodpressureData", userBloodpressureDataServiceImpl.selectUserBloodpressureDataById(id));
        }else{
            mmap.put("userBloodpressureData", new UserBloodpressureData());
        }
        return prefix + "/form";
    }


    /**
     * 新增保存用户血压数据
     */
    @RequiresPermissions("product:userBloodpressureData:edit")
    @Log(title = "用户血压数据", businessType = BusinessType.INSERT)
    @PostMapping("/saveOrUpdate")
    @ResponseBody
    public AjaxResult saveOrUpdate(UserBloodpressureData userBloodpressureData)
    {
        return toAjax(userBloodpressureDataServiceImpl.saveOrUpdate(userBloodpressureData));
    }

    /**
     * 删除
     */
    @RequiresPermissions("product:userBloodpressureData:remove")
    @Log(title = "用户血压数据", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(Long id)
    {
        return toAjax(userBloodpressureDataServiceImpl.deleteById(id));
    }


    /**
     * 导出用户血压数据列表
     */
    @RequiresPermissions("product:userBloodpressureData:export")
    @Log(title = "用户血压数据", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(UserBloodpressureData userBloodpressureData)
    {
        List<UserBloodpressureData> list = userBloodpressureDataServiceImpl.selectUserBloodpressureDataList(userBloodpressureData);
        ExcelUtil<UserBloodpressureData> util = new ExcelUtil<UserBloodpressureData>(UserBloodpressureData.class);
        return util.exportExcel(list, "用户血压数据数据");
    }

}
